(function () {
    var $vs = function (tabObj) {
        this.tabObj = tabObj;
    };

    $vs.prototype = {
        init:function(){
            //普通搜索字段change事件
            $('#normalFieldName').bind('change',function(){
                //隐藏 input
                $.each($('.normalSearchGroup input'),function () {
                    $(this).val('');
                    $(this).parents('.form-horizontal').eq(0).hide();
                });
                //隐藏 select
                $.each($('.normalSearchGroup select'),function () {
                    $(this).val('');
                    $(this).parents('.form-horizontal').eq(0).hide();
                });
                //显示当前搜索条件
                var values = this.value.split(';');
                for (var i = 0; i < values.length; i++) {
                    $('.normalSearchGroup [name="'+values[i]+'"]').parents('.form-horizontal').eq(0).show();
                }
            });
            return this;
        },
        //普通搜索特殊检索条件
        normalSpecialDataFun:function () {
            return {};
        },
        //高级搜索特殊检索条件
        highSpecialDataFun:function () {
            return {};
        },
        //公共搜索特殊检索条件
        specialDataFun:function () {
            return {};
        },
        //高级搜索 整合查询数据
        highCollectData: function () {
            var me = this;
            var queryData = {};
            $.each($('.highSearchGroup input'), function () {
                queryData[this.name] = $.trim(this.value);
            });
            $.each($('.highSearchGroup select'), function () {
                queryData[this.name] = $.trim(this.value);
            });
            queryData = $.extend({},queryData,me.specialDataFun());//添加公共特殊方法
            queryData = $.extend({},queryData,me.highSpecialDataFun());//添加高级搜索特殊方法
            console.log(queryData);
            return queryData;
        },
        //高级搜索
        highSearch: function () {
            var me = this;
            me.tabObj.refresh({query: me.highCollectData()});
        },
        //高级搜索 清空
        highResetSearch: function () {
            //隐藏 input
            $.each($('.highSearchGroup input'), function () {
                $(this).val('');
            });
            //隐藏 select
            $.each($('.highSearchGroup select'), function () {
                $(this).val('');
                //更新chosen select插件选择状态
                $(this).trigger("chosen:updated");
            });

        },
        //普通搜索 整合查询数据
        normalCollectData: function () {
            var me = this;
            //清空高级搜索 勿删！！
            me.highResetSearch();
            //初始为已清空的 高级搜索条件 即所有条件都为空
            //var queryData = me.highCollectData();
            var queryData = {};
            // {搜索字段:搜索字段值}
            var values = $('#normalFieldName').val().split(';');
            for (var i = 0; i < values.length; i++) {
                queryData[values[i]] = $.trim($('.normalSearchGroup [name="' + values[i] + '"]').val());
            }
            queryData = $.extend({},queryData,me.specialDataFun());//添加公共特殊方法
            queryData = $.extend({},queryData,me.normalSpecialDataFun());//添加普通搜索特殊方法
            console.log(queryData);
            return queryData;
        },
        //普通搜索
        normalSearch: function () {
            var me = this;
            me.tabObj.refresh({query: me.normalCollectData()});
        },

        set: function (attr, val) {
            this[attr] = (typeof value == "undefined") ? "" : val;
            return this;
        },

        setHighCollectData: function (data) {
            this.highCollectData = data;
            return this;
        },
        setHighSearch: function (data) {
            this.highSearch = data;
            return this;
        },
        setHighResetSearch: function (data) {
            this.highResetSearch = data;
            return this;
        },

        setNormalCollectData: function (data) {
            this.normalCollectData = data;
            return this;
        },
        setNormalSearch: function (data) {
            this.normalSearch = data;
            return this;
        },
        setTabObj: function (data) {
            this.tabObj = data;
            return this;
        },


        //普通搜索特殊检索条件
        setNormalSpecialDataFun:function (data) {
            this.normalSpecialDataFun = data;
            return this;
        },
        //高级搜索特殊检索条件
        setHighSpecialDataFun:function (data) {
            this.highSpecialDataFun = data;
            return this;
        },
        //公共搜索特殊检索条件
        setSpecialDataFun:function (data) {
            this.specialDataFun = data;
            return this;
        },

    };

    window.$vs = $vs;

}());